package cn.com.common;

/**
 * @author jiaming
 */
public class Constant {

    public static final int MAX_PAYLOAD = 8 * 1024 * 1024;

    public static final short MAGIC = (short) 0xca1100;

    public static final byte REQUEST = (byte) 0;

    public static final byte RESPONSE = (byte) 1;

    public static final byte ONEWAY = (byte) 3;

    public static final boolean DEFAULT_ONEWAY = true;

    public static final String DEFAULT_ONEWAY_KEY = "default.oneway.key";

    public static final int DEFAULT_HEARTBEAT_TIMEOUT = 60 * 1000;

    public static final String HEARTBEAT_TIMEOUT = "heartbeat.timeout";

    public static final String VERSION_DEFAULT_VALUE = "0.0.0";

    public static final byte KRYO_SERIALIZE = 0;

    public static final byte PROTOBUF_SERIALIZE = 1;

    public static final int HEADER_LENGTH = 17;

    public static final int MSG_LENGTH_OFFSET = 13;

    public static final int TIMEOUT = 5000;

    public static final int CONNECT_TIMEOUT = 5000;

    public static final byte SUCCESS = 0;

    public static final byte REQUEST_TIMEOUT = 1;

    public static final byte RESPONSE_TIMEOUT = 2;

    public static final byte BAD_REQUEST = 3;

    public static final byte BAD_RESPONSE = 4;

    public static final int RETRY_NUMS = 2;

    public static final String RETRY_KEY = "retry";

    public static final int NAME_SERVICE_TIMEOUT = 5000;

    public static final String GROUP = "group";

    public static final String GROUP_DEFAULT_VALUE = "default";

    public static final String IO_DECODER = "io_decoder";

    public static final boolean IO_DECODER_DEFAULT_VALUE = false;

    public static final String IO_THREAD = "io_thread";

    public static final int IO_THREAD_DEFAULT_NUM = Math.min(Runtime.getRuntime().availableProcessors() + 1, 32);

    public static final int WORKER_THREAD_DEFAULT_NUM = Math.min(Runtime.getRuntime().availableProcessors() + 1, 16);

    public static final String VERSION = "version";

    /*client constant*/

    public static final int CACHE_DEFAULT_VALUE=0x0000000;

    public static final String APP_NAME = "default";

    public static final int CLIENT_PORT = 20088;

    public static final int QUEUE_SIZE = 1000;

    public static final int QUEUE_OFFER_WAIT = 200;

    /* registry constant*/

    public static final int ETCD_PORT = 2379;

    public static final String ETCD_HOST = "127.0.0.1";

    public static final String APPLICATION_PATH = "/zhurong-apps";

    public static final String SERVER_PATH = "/zhurong-servers";

    public static final String RULE_PATH = "/zhurong-rules";

    public static final String WHITELIST_PATH = "/zhurong-whitelist";

    public static final int DEFAULT_REGISTRY_RETRY_PERIOD = 5 * 1000;

    public static final int DEFAULT_KEEPALIVE_TIMEOUT = 30 * 1000;

    public final static String PATH_SEPARATOR = "/";

    public static final String COMMA_SEPARATOR = ",";

    public static final String HTTP_SUBFIX_KEY = "://";

    public static final String HTTP_KEY = "http://";

    public static final int DEFAULT_REGISTRY_RECONNECT_PERIOD = 3 * 1000;

    public static final int DEFAULT_SESSION_TIMEOUT = 60 * 1000;

    public static final int DEFAULT_GRPC_QUEUES = 300_0000;

    /* cache constant */

    public static final int CACHE_MIN_SIZE = 128;

    public static final int CACHE_MAX_SIZE = 65535;

    public static final int EXPIRE_TIME = 60;

    /**
     * 即将过期的阈值，单位：ms
     */
    public static final long NEAR_EXPIRATION_THRESHOLD = 500L;

    /*server*/

    /**
     * server端默认端口号
     */
    public static final int SERVER_PORT = 20079;

    public static final String SERVER_NAME = "zhurong";

    public static final int SERVER_KEY_CACHE_MAX = 5000000;

    public static final int SERVER_KEY_CACHE_MIN = 8192;

}
